"use strict";

/**
 * @ngdoc directive
 * @name jgappApp.directive:logList
 * @description
 * # logList
 */
angular.module("jgappApp").directive("logList", [
  "Util",
  "openApi",
  "OpenFile",
  function(Util, openApi, OpenFile) {
    return {
      scope: {
        taskid: "=taskid",
        status: "=status"
      },
      replace: true,
      template: '<div class="log-list" ng-show="logData.length>0">' +
        '<div class="info-title">审批记录</div>' +
        '<div class="list-item log-item fs14 lh25 {{item.className}}" ng-repeat="item in logData">' +
        '<div class="flex">' +
        '<p class="c0 fs16 w70">{{item.assigneeName}} [{{item.name_}}] </p>' +
        '<p class="w30 tr">{{item.operationResult}}</p>' +
        "</div>" +
        '<p><span ng-bind-html="item.aduitDesc|parsetohtml" class="c0"></span></p>' +
        '<p class="c0" ng-if="item.taskDefinitionKey">快递单号:<span class="c-succ celled" ng-click="checkDefinitionKey(item.taskDefinitionKey)">{{item.taskDefinitionKey}}</span></p>' +
        '<div class="list-item" file-list file-data="item.description_" hidelabel="true" checked="true"></div>' +
        '<p class="c9 w70">{{item.endTime}}</p>' +
        "</div>" +
        "</div>",
      restrict: "AE",
      link: function postLink(scope, element, attrs) {
        // element.text('this is the logList directive');
        scope.$watch("taskid", function(newValue) {
          if (newValue) {
            Util.showloglist(newValue, function(data) {
              scope.logData = data;
            });
          }
        });
        // scope.checkDefinitionKey = function (id) {
        //     Util.openExpress(id);
        // }
        scope.checkDefinitionKey = function(id) {
          var href = "https://m.kuaidi100.com/result.jsp?com=&nu=" + id;
          // ios & android are opened in the different way
          OpenFile.showFile(href)
        };
        scope.goDetail = function(fileData, index) {
          if (Util.isImg(fileData)) {
            var param = {};
            param.data = fileData;
            param.index = 0;
            param.showbtn = true;
            NativeUtil.use("photoPreview", null, param);
          } else if (Util.isFile(fileData)) {
            OpenFile.open(fileData);
          } else {
            Util.Toast("移动端不支持预览");
          }
        };
      }
    };
  }
]);
